#!/bin/bash

INSTALL=
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh

REAL_COMMAND=$(get_command apt-get)
if [ -z "$REAL_COMMAND" ]; then
    echo "The command apt-get does not exist." 1>&2
    exit 1
fi

VERSION_FILE="/usr/local/share/buildinfo/versions/versions-deb"
if [ "$ENABLE_VERSION_CONTROL_DEB" == "y" ]; then
    for para in $@
    do
        if [[ "$para" != -* ]]; then
            continue
        fi
        if [ ! -z "$INSTALL" ]; then
            if [[ "$para" == *=* ]]; then
                continue
            elif [[ "$para" == *=* ]]; then
                continue
            else
                package=$para
                if ! grep -q "^${package}=" $VERSION_FILE; then
                    echo "The version of the package ${package} is not specified."
                    exit 1
                fi
            fi
        elif [[ "$para" == "install"  ]]; then
            INSTALL=y
        fi
    done
fi


$REAL_COMMAND "$@"
